<?php
/**
* @version		$Id: helper.php 7331 2007-05-03 22:33:59Z jinx $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

class modBookstoreHelper
{
	function getReturnURL($params,$type)
	{
		// url of current page that user will be returned to after login
		//$url =  $params->get($type);
		
		//if($url == ''){
		$array = array(
					'option'=>'com_bookstore',
					'view'=>'bookstore'
				);
			$prev_uri =& JURI::getInstance();
		if($itemid = $prev_uri->getVar('Itemid')){
			$array['Itemid'] = $itemid;
		}
		//} else {
		//	$uri =& JURI::getInstance($url);
		//}
		//$path = JURI::base();
		//$path .= 'index?';
		$new_url = new JURI();
		$new_url->setPath($prev_uri->getPath());
		$str = $new_url->setQuery( $new_url->buildQuery($array) );
		
		
		//		$url = $params->get('component_url');
		//return $new_url->toString( array('query'=>$str) );
		return $new_url->toString(array('path','query'));
		//return $str;
	}

	function getType()
	{
		$user = & JFactory::getUser();
	    return (!$user->get('guest')) ? 'logout' : 'login';
	}
	
	function getFormLayout($mod_layout = 0){
	
		if( (int)$mod_layout == 1){
			$layout = JModuleHelper::getLayoutPath('mod_bookstore');
			$layout = substr($layout, 0,-11).'extended.php';
			return $layout;
		}
		else if( (int)$mod_layout == 2 ){
			$layout = JModuleHelper::getLayoutPath('mod_bookstore');
			$layout = substr($layout, 0, -11).'main_page.php';
			return $layout;
		}
		else{
			//$layout = normal;
			$layout = JModuleHelper::getLayoutPath('mod_bookstore');
			return	$layout;
		}//end if
		
	}//end function
	
	function getExtForm(){
		//for loading XML form
		jimport('joomla.html.pane');

		$pane	=& JPane::getInstance('sliders');
		$xml = substr(JModuleHelper::getLayoutPath('mod_bookstore'), 0, -11).'extended.xml';
		$form = new JParameter( '', $xml);	
		$form->loadINI($this->selection->params);
		
		echo $pane->startPane("content-pane");
		
		$title = JText::_( 'Simple Query' );
		echo $pane->startPanel( $title, "detail-page" );
		echo $form->render();
		echo $pane->endPanel();
		
		$title = JText::_( 'Advanced Query' );
		echo $pane->startPanel( $title, "params-page" );
		echo $form->render('params', 'advanced');
		echo $pane->endPanel();
		
		echo $pane->endPane();
	}
}//end helper class